package com.du.spring5.bean;

import com.du.spring5.bean.Department;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

/**
 * @author : DuJiabao
 * @Date : 2021/2/3 21:38
 * @Project : spring
 * @File : null.java
 * @Desc :
 * 配置对象一共有四种注解，都可以用，主要看对象在哪个层 `@Component`、`@Service`、`@Controller`、`@Repository`
 */
//@Component(value="user")
@Component// 等效于上方
public class User {
    @Value(value = "abc") // 用于注入普通类型属性
    private String name;
    private int id;
    // 自动属性注入，方法：需要被注入的类型属性，首先创建对象注解。然后在属性上面加Autowired
    @Autowired // 根据类型注入
    @Qualifier(value = "dptm") // 根据名称注入，应用于一个类型有多个不同名称的对象时候。如果类就可以定位，那么该注解可以省略
    private Department department;

    public User() {
    }

    public User(String name, int id) {
        this.name = name;
        this.id = id;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setId(int id) {
        this.id = id;
    }

    public void setDepartment(Department department) {
        this.department = department;
    }

    @Override
    public String toString() {
        return "User{" +
                "name='" + name + '\'' +
                ", id=" + id +
                ", department=" + department +
                '}';
    }
}
